<template>
	<view class="container">
		<u-modal v-model="show" :content="content" :show-confirm-button="false"></u-modal>
		<u-picker v-model="sho" @confirm="datali" @cancel="datail" mode="region" :mask-close-able="false"> </u-picker>
		<view class="head">
			<view @click="tag">
				<view>
					<u-icon label="" size="40" name="arrow-down" v-show="nearby"></u-icon>
					<u-icon label="" size="40" name="arrow-up" v-show="nearby1"></u-icon>
				</view>
				<view>
					附近
				</view>
			</view>
		</view>
		<headnav :list="listtxt" :index="index" @parsebtn="toggle"></headnav>
		<view class="cons">
			<view class="con" v-for="(val,ind) in datalist" :key="ind" >
				<view class="left" @click="router(val.userId,isvip,val.areaId)">
					<view class="img">
						<image :src="val.pic" mode="aspectFill" :class="[ ger.sex == val.sex  ? 'iim' : '']" ></image>
					</view>
					<!-- <view class="le-txt" v-if="val.userTitle==1">
						魅力女生
					</view> -->
				</view>
				<view class="right">
					<view class="ri-one" @click="router(val.userId,isvip,val.areaId)">
						<view class="le" >
							<view class="user" >
								{{val.nickName}}
							</view>
							<!-- <view class="status">
								{{val.isOnline=='0'?'不在':'在线'}}
							</view> -->
						</view>
						<view class="ri" @click="router(val.userId,isvip,val.areaId)">
							{{val.province||'上海'}}
						</view>
					</view>
					<view class="ri-two">
						<view class="le">
							{{val.areaId.sex=='F'?'女':'男'}} · {{val.areaId.age}}岁
						</view>
						<view class="ri" @click="like(val.userId,val.isLiked,val.areaId)">
							<view class="love">
								<image
									:src="val.isLiked==0?'../../static/dongtai-like01.png':'../../static/dongtai-like.png'"
									mode="aspectFit" class="lovel"></image>
								<image class="loveI" src="../../static/vip.png" mode="widthFix" v-if="val.isVip==1"></image>
							</view>
							<view class="txt">
								喜欢
							</view>
						</view>
					</view>
					<view class="ri-three" @click="router(val.userId,isvip,val.areaId)">
						{{val.areaId.synopsis}}
					</view>
					<view class="ri-four">
						
						<view class="label"  @click="router(val.userId,isvip,val.areaId)" >
							{{val.height == null ? "175" : val.height == "" ? "170" : val.height}}cm
						</view>
						<view class="label"  @click="router(val.userId,isvip,val.areaId)">
							{{val.areaId.weight/2}}kg
						</view>
						<view class="label"  @click="router(val.userId,isvip,val.areaId)">
							{{val.areaId.profession == null ? "学生" : val.areaId.profession == "" ? "学生" : val.areaId.profession}}
						</view>
						<view class="label"  @click="router(val.userId,isvip,val.areaId)">
							{{val.areaId.province == null ? "上海市" : val.areaId.province == "" ? "北京市" : val.areaId.province}}
						</view>
						<view class="label"  @click="router(val.userId,isvip,val.areaId)">
							{{val.distance == null ? "全国可飞"  : Math.round(val.distance)+'km'}}
						</view>
						<view class="label"  @click="router(val.userId,isvip,val.areaId)">
							{{val.isOnline == 1 ? "在线"  : "离线" }}
						</view>
						<!-- <view>
							{{val.userLabels}}
						</view> -->
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import headnav from "../../components/headnav/index"
	import * as api from '@/api/api.js'
	export default {
		components: {
			headnav
		},
		data() {
			return {
				listtxt: [{
					id: 1,
					txt: "全部"
				}, {
					id: 2,
					txt: "距离优先"
				}, {
					id: 3,
					txt: "新人优先"
				}],
				index: 0,
				list: [{
					id: 1
				}, {
					id: 2
				}, {
					id: 3
				}],
				datalist: "",
				ger:"",
				nearby: true,
				nearby1: false,
				isvip:0,
				sho:false,
				profession:[],
				arrpp:[],
				afff:"",
				show: false,
				content: '请打开GPS定位后退出重新登录来获取附近信息',
				amapPlugin: null,  
				key: 'ac163873d2de8eb16deeebccc0a9f0aa',
				addressName: '',
				weather: {  
					hasData: false,  
					data: []  
				}
			}

		},
		onPullDownRefresh() {
			this.getlist()
			setTimeout(function () {
				uni.stopPullDownRefresh();  //停止下拉刷新动画
			}, 1000);
		},
		onReady(){
			console.log('初次')
			// this.getlist()
			
		},
		onShow() {
			console.log('定位1')
			this.getlist()
			let that = this
			uni.getLocation({
				type: 'wgs84',
				geocode:true,//设置该参数为true可直接获取经纬度及城市信息
				success: function (res) {
					console.log('位置名称：' + res.name);
					console.log('详细地址：' + res.address);
					console.log('纬度：' + res.latitude);
					console.log('经度：' + res.longitude);
					api.request({
						url: '/p/dist/editDistance',
						method: 'GET',
						data:{
							lng: res.longitude,
							lat: res.latitude
						}
					}).then(res => {
						console.log('获取成功地址')
						that.getlist()
					});
				},
				fail: function () {
					that.show = true;
					setTimeout(function(){
						that.show = false;
					},3000)
				}
			});
		},
		onHide() {
			this.getlist()
			// this.huoqu()
			let that = this
			console.log('定位1')
		},
		
		mounted() {
			this.getlist()
		},
		onLoad() {
		},
		methods: {
			
			//获取个人信息
			// huoqu(){
			// 	api.request({
			// 		url: '/p/user/userInfo',
			// 		method: 'GET',
			// 	}).then(set => {
			// 		this.ger = set.data
			// 		console.log(this.ger.sex)
			// 	})
			// },
			tag() {
				this.nearby = false
				this.nearby1 = true
				this.sho = true
			},
			datali(rrr){
				api.request({
					url: "/p/main/loc",
					method: 'GET',
					data: {
						prov: rrr.province.label,
						city: rrr.city.label
					},
				}).then(res => {
					for (let item in res.data) {
						if (res.data[item].userLabels == null) {
							console.log("空");
							
						} else {
							res.data[item].userLabels = res.data[item].userLabels.split(',')
							
						}
					}
					this.datalist=res.data
					this.datalist.forEach((item,index,arrr)=>{
						let arr = {}
						// console.log(item.userLabels,index)
						if(index == 5) {
							console.log(item)
						}
						if(item.age == null){
							arr.age = 18
						}else{
							arr.age = item.age
						}
						arr.height = item.height
						// console.log(item)
						arr.sex = item.sex
						let oop = "2021-07-07 17:22:29"
						var uew = new Date(Date.parse(item.userRegtime.replace(/-/g, "/"))); 
						var uew1 = new Date(Date.parse(oop.replace(/-/g, "/")))
						if(uew.getTime()>=uew1.getTime()){
							let arr1 = JSON.parse(item.userLabels)
							arr.cityId = arr1
							// console.log(arr1)
							arr.profession = arr1.profession
							arr.province = item.province
							arr.synopsis = arr1.synopsis
						}
						if(item.weight == null){
							arr.weight = 96
						}else{
							arr.weight = item.weight
						}
						this.datalist[index].areaId = arr
					})
					// console.log(this.datalist)
					// console.log(78952626)
					api.request({
						url: '/p/unlock',
						method: 'GET',
					}).then(set => {
						this.arrpp = set.data
						// console.log(this.arrpp)
					})
				})
			},
			datail(rrr){
				this.nearby = true
				this.nearby1 = false
				uni.showToast({
					title: '你没有选择',
					icon: 'none'
				})
			},
			shaix(shi){
				if(shi == 0){
					this.getlist('/p/main/onl')
				}
				if(shi == 1){
					this.getlist('/p/main/dis')
				}
				if(shi == 2){
					this.getlist('/p/main/news')
				}
			},
			toggle(e) {
				this.index = e;
				this.shaix(e)
			},
			router(id,vip,dad) {
				let a
				// console.log(id,vip,dad,this.arrpp)
				uni.setStorage({
				    key: 'daad',
				    data: dad,
				    success: function () {
				        console.log('success');
				    }
				});
				for (let s of this.arrpp){
					// console.log(s)
					// console.log(s.unlockedUserId == id)
					if(s.unlockedUserId == id){
						a = 1
					}
				}
				// console.log(a)
				this.$u.route("pages/user/userinfo/userinfo", {
					id: id,
					vip: vip,
					ck: a
				})
			},
			like(id, type) {
				// console.log(id, type,this.datalist);
				// 1 是喜欢
				if (type == 1) {
					api.request({
						url: '/p/user/like/' + id,
						method: 'DELETE',
					}).then(res => {
						// console.log(id);
						this.getlist()
					})
				} else {

					api.request({
						url: '/p/user/like/' + id,
						method: 'PUT',
					}).then(res => {
						// console.log(id);
						this.getlist()
					})
				}


			},
			async getlist(res = '/p/main/onl') {
				api.request({
					url: res,
					method: 'GET',
					data: {},
				}).then(res => {
					console.log(res)
					for (let item in res.data) {
						if (res.data[item].userLabels == null) {
							console.log("空");
							
						} else {
							res.data[item].userLabels = res.data[item].userLabels.split(',')
							
						}
					}
					this.datalist=res.data
					this.datalist.forEach((item,index,arrr)=>{
						let arr = {}
						// console.log(item.userLabels,index)
						if(index == 5) {
							console.log(item)
						}
						if(item.age == null){
							arr.age = 18
						}else{
							arr.age = item.age
						}
						arr.height = item.height
						// console.log(item)
						arr.sex = item.sex
						let oop = "2021-07-07 17:22:29"
						var uew = new Date(Date.parse(item.userRegtime.replace(/-/g, "/"))); 
						var uew1 = new Date(Date.parse(oop.replace(/-/g, "/")))
						if(uew.getTime()>=uew1.getTime()){
							let arr1 = JSON.parse(item.userLabels)
							arr.cityId = arr1
							// console.log(arr1)
							arr.profession = arr1.profession
							arr.province = item.province
							arr.synopsis = arr1.synopsis
						}
						if(item.weight == null){
							arr.weight = 96
						}else{
							arr.weight = item.weight
						}
						this.datalist[index].areaId = arr
					})
					// console.log(this.datalist)
					// console.log(78952626)
					api.request({
						url: '/p/unlock',
						method: 'GET',
					}).then(set => {
						this.arrpp = set.data
						console.log(this.arrpp)
					})
					api.request({
						url:'/p/user/userInfo',
						method:'GET',
						data:{}
					}).then(res =>{
						// console.log(res)
						this.isvip = res.data.isVip
						this.ger = res.data
						console.log(this.ger.sex)
					})
				})
				
				
			}
		}
	}
</script>

<style>
	page {
		background-color: #3b3b43;
	}
	
	.uni-scroll-view {
		background-color: #000000;
	}
	
	.head {
		width: 750rpx;
		text-align: center;
		height: 80rpx;
		display: flex;
		line-height: 80rpx;
		margin-top: 50rpx;
		color: #ffb23f;
	}

	.head>view {
		width: 100rpx;
		border: 1 rpx solid black;
		margin: 0 auto;
	}

	.head>view {
		display: flex;
	}

	.head>view>view:nth-child(1) {
		margin-top: 4rpx;
	}

	.cons {
		display: flex;
		flex-direction: column;
		/* margin-top: 10rpx; */
		/* padding-bottom: 120rpx; */
	}

	.cons .con {
		height: 300rpx;
		margin: 10rpx 5px;
		display: flex;
		flex-direction: row;
		justify-content: space-around;
		align-items: center;
		margin-bottom: 20rpx;
		background-color: #3b3b43;
	}

	.cons .con .left {
		width: 30%;
		display: flex;
		flex-direction: column;
		justify-content: space-around;
		align-items: center;
		position: relative;
	}
	
	.loveI {
		width: 50rpx;
		height: 30rpx;
		position: absolute;
		top: -62rpx;
		left: -490rpx;
		//#ifdef APP-PLUS
		left: -500rpx;
		//#endif
	}
	
	.cons .con .left .img {
		width: 100%;
		height: 300rpx;
		position: absolute;
		top: -160rpx;
		left: 0rpx;
	}

	.cons .con .left .img image {
		max-width: 85%;
		max-height: 85%;
		border-radius: 10rpx;
		margin-top: 32rpx;
		margin-left: 20rpx;
		/* 		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%); */
	}
	
	.iim{
		filter: blur(10rpx);
	}
	
	.cons .con .left .le-txt {
		width: 150rpx;
		height: 55rpx;
		line-height: 55rpx;
		text-align: center;
		font-size: 26rpx;
		background-color: orange;
		color: #ffb23f;
		border-radius: 30rpx;
		margin: 10rpx auto;
	}

	.cons .con .right {
		width: 68%;
		display: flex;
		flex-direction: column;
		margin: 0 1%;
		margin-left: 20rpx;

	}

	.cons .con .right .ri-one,
	.ri-two {
		height: 65rpx;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

	}

	.cons .con .right .ri-one .le {
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		color: #ffb23f;
	}

	.cons .con .right .ri-one .le .user {
		margin-right: 10rpx;
		font-size: 36rpx;
		color: #FFFFFF;
	}

	.cons .con .right .ri-one .le .status {
		background-color: #ffb23f;
		border-radius: 20rpx;
		font-size: 26rpx;
		width: 100rpx;
		text-align: center;
		height: 45rpx;
		line-height: 45rpx;
		color: #FFFFFF;
	}

	.cons .con .right .ri-one .ri {
		font-size: 24rpx;
		color: white;
		background-color: #696969;
		padding: 6rpx 24rpx;
		border-radius: 20rpx;
	}

	.cons .con .right .ri-two .le {
		margin-left: 10rpx;
		color: #FFA800;
	}
	
	.cons .con .right .ri-two .ri {
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		align-items: center;
		color: #ffb23f;
	}

	.cons .con .right .ri-two .ri .love {
		width: 30rpx;
		height: 30rpx;
		position: relative;
	}

	.cons .con .right .ri-two .ri .love .lovel {
		max-width: 100%;
		max-height: 100%;
	}
	
	.cons .con .right .ri-three {
		height: 38rpx;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-indent: 10rpx;
		margin: 20rpx 0;
		color: #ffb23f;
	}

	.cons .con .right .ri-four {
		height: 90rpx;
		display: flex;
		flex-direction: row;
		justify-content: flex-start;
		align-items: center;
		flex-wrap: wrap;
	}

	.cons .con .right .ri-four::after {
		display: block;
		content: "";
		width: 100%;
		height: 1px;
		background-color: #999999;
		margin-top: 14rpx;
	}

	.cons .con .right .ri-four .label {
		background-color: #1e1920;
		border-radius: 20rpx;
		text-align: center;
		height: 45rpx;
		line-height: 45rpx;
		margin-right: 10rpx;
		margin-bottom: 5rpx;
		padding: 0 10rpx;
		color: #ffb23f;
		padding: 0rpx 20rpx;
	}
</style>
